
<style type="text/css">
/* 添加商品 */

#js_add_good_form_tab{margin-top:10px;}
#add_good_form_div{border-top:1px solid #ccc;}
#js_tab_title_block ul{border-bottom:1px solid #ccc;}
#js_tab_title_block .js_tab_title_li{
    display:inline-block; width:80px; margin-right:5px; padding:5px; border:1px solid #ccc; border-bottom:0px;
    list-style:none; text-align:center; cursor:pointer;
}
#js_tab_title_block .js_tab_title_li.active{background:#cccccc; border:0px;}
#js_tab_content_block .js_tab_content_div{padding:10px; display: none;}
#js_tab_content_block #base_attrs{display: block}
#add_good_form .form_content{padding: 10px;}

#good_attr_clone{display:none;}
#good_sattr_clone{display:none;}
#good_spec_clone{display:none;}
#good_spec_list_label_col_clone{display:none;}
#good_spec_list_input_col_clone{display:none;}

#add_good_form .form_content .unit .attr_lable{width:124px;text-align:left;}
#add_good_form .form_content .unit .attr_input{width:120px; text-align:left;}

#good_spec_list{overflow:auto;}
#good_spec_list .unit{white-space:nowrap;}

#content .form_content #good_spec_list .unit_odd{margin:0; padding:10px; background:#f3f3f3;}
#content .form_content #good_spec_list .unit_even{margin:0; padding:10px; background:#e9e9e9;}


#image_file_upload_div{display:inline-block;}
.uploadify-button-text{ color: #fff; /* display:inline-block; position:absolute; top:8%; left:40%; */}    /* uploadify 修改【上传按钮】内部样式 */
.image_div .image_div_img{display:inline-block; position:relative; width:120px; height:120px; margin-right:10px; border:1px solid #ccc; /*padding: 6px;*/ }
.image_div .image_div_img img{width:120px; height:120px;}
.image_div .image_div_img a{display:none;}
.image_div .image_div_img:hover a{display:inline-block; position:absolute; top:0; right:0; border-left:1px solid #ccc; border-bottom:1px solid #ccc;
    background:#fff; z-index:999; cursor:pointer; text-decoration:none;}

#add_good_form .good_name{width: 500px;}
#textarea_after_sale_service{width:710px; height:500px;}


#good_number_grade_clone{display: none;}
#good_spec_list_number_grade_clone{display: none;}
#add_good_form .form_content .unit .spec_number_grade_div{margin:10px; padding: 10px; background: #fff;}
#content .form_content .unit span.spec_number_grade_number_min{margin:0;}
#content .form_content .unit span.spec_number_grade_number_max{margin:0;}


</style>


<div class="current_location">
    <ul>
        <li><a>当前位置：</a></li>
        <li><a>商品管理</a></li>
        <li> > <a><?php if(!empty($view_data['good_info']['id'])): ?>编辑商品<?php else: ?>新增商品<?php endif ?></a></a></li>
    </ul>
</div>


<form id="add_good_form" method="post" action="<?php echo $view_data['save_url']; ?>"  onsubmit="return save_good();">
    <?php if(!empty($view_data['good_info']['id'])): ?>
        <input type="hidden" name="id" value="<?php echo $view_data['good_info']['id']; ?>" />
    <?php endif ?>

    <div id="js_add_good_form_tab">
        <blockquote id="js_tab_title_block">
            <ul>
                <li class="js_tab_title_li active">基本信息</li>
                <li class="js_tab_title_li">属性</li>
                <li class="js_tab_title_li">规格</li>
                <li class="js_tab_title_li">描述</li>
                <li class="js_tab_title_li">售后服务</li>
            </ul>
        </blockquote>

        <blockquote id="js_tab_content_block">
            <div id="base_attrs" class="js_tab_content_div form_content">
                <div class="unit">
                    <label>商品名称：</label>
                    <input class="good_name" name="name" type="text" value="<?php if(!empty($view_data['good_info'])): echo $view_data['good_info']['name']; endif; ?>" />
                </div>

                <div class="unit">
                    <label>商品分类：</label>
                    <select name="cat_id">
                        <option value="0">顶级</option>

                        <?php foreach ($view_data['all_category_list'] as $category): ?>
                        <option value="<?php echo $category['id']; ?>" <?php if(!empty($view_data['good_info']) && $category['id'] === $view_data['good_info']['cat_id']): echo 'selected="selected"'; endif ?> >
                            <?php
                            for($i = 1; $i < $category['level']; $i++){
                                echo '&nbsp;&nbsp;';
                            }
                            ?>
                            <?php echo $category['name']; ?>
                        </option>
                        <?php endforeach ?>
                    </select>
                </div>

                <div class="unit">
                    <label>简述：</label>
                    <?php /*
                    <input name="brief" type="text" value="<?php if(!empty($view_data['good_info'])): echo $view_data['good_info']['brief']; endif; ?>" />
                    */ ?>
                    <textarea class="textarea_brief" name="brief"><?php if(!empty($view_data['good_info'])): echo $view_data['good_info']['brief']; endif; ?></textarea>
                </div>
                <div class="unit">
                    <label>排序：</label>
                    <input class="valid" name="order" type="text" value="<?php if(!empty($view_data['good_info'])): echo $view_data['good_info']['order']; endif; ?>" />
                </div>
                <div class="unit">
                    <label>状态：</label>
                    <select name="status">
                        <option value="1" <?php if((!empty($view_data['good_info'])) && $view_data['good_info']['status'] == '1'): ?>selected="selected"<?php endif; ?>>上架</option>
                        <option value="0" <?php if((!empty($view_data['good_info'])) && $view_data['good_info']['status'] == '0'): ?>selected="selected"<?php endif; ?>>下架</option>
                    </select>
                </div>

                <div class="image_div">
                    <div class="unit">
                        <label>图片：</label>
                        <div id="image_file_upload_div"><input type="file" name="image_file_upload" id="image_file_upload" /></div>
                    </div>

                    <div class="unit">
                        <label>&nbsp;</label>
                        <div id="image_div_img_0" class="image_div_img"><?php if(!empty($view_data['good_info']['image_thumb'][0])): ?><img src="<?php echo $view_data['good_info']['image_thumb'][0]; ?>" /><a title="删除" onclick="delete_image(0);">X</a><?php endif; ?></div>
                        <input id="image_0" type="hidden" name="image_arr[0]" value="<?php if(!empty($view_data['good_info']['image_arr'][0])): echo $view_data['good_info']['image_arr'][0]; endif;?>" />
                        <div id="image_div_img_1" class="image_div_img"><?php if(!empty($view_data['good_info']['image_thumb'][1])): ?><img src="<?php echo $view_data['good_info']['image_thumb'][1]; ?>" /><a title="删除" onclick="delete_image(1);">X</a><?php endif ?></div>
                        <input id="image_1" type="hidden" name="image_arr[1]" value="<?php if(!empty($view_data['good_info']['image_arr'][1])): echo $view_data['good_info']['image_arr'][1]; endif;?>" />
                        <div id="image_div_img_2" class="image_div_img"><?php if(!empty($view_data['good_info']['image_thumb'][2])): ?><img src="<?php echo $view_data['good_info']['image_thumb'][2]; ?>" /><a title="删除" onclick="delete_image(2);">X</a><?php endif ?></div>
                        <input id="image_2" type="hidden" name="image_arr[2]" value="<?php if(!empty($view_data['good_info']['image_arr'][2])): echo $view_data['good_info']['image_arr'][2]; endif;?>" />
                        <div id="image_div_img_3" class="image_div_img"><?php if(!empty($view_data['good_info']['image_thumb'][3])): ?><img src="<?php echo $view_data['good_info']['image_thumb'][3]; ?>" /><a title="删除" onclick="delete_image(3);">X</a><?php endif ?></div>
                        <input id="image_3" type="hidden" name="image_arr[3]" value="<?php if(!empty($view_data['good_info']['image_arr'][3])): echo $view_data['good_info']['image_arr'][3]; endif;?>" />

                        <br/><br/>
                        <label>&nbsp;</label>
                        <div id="image_div_img_4" class="image_div_img"><?php if(!empty($view_data['good_info']['image_thumb'][4])): ?><img src="<?php echo $view_data['good_info']['image_thumb'][4]; ?>" /><a title="删除" onclick="delete_image(4);">X</a><?php endif ?></div>
                        <input id="image_4" type="hidden" name="image_arr[4]" value="<?php if(!empty($view_data['good_info']['image_arr'][4])): echo $view_data['good_info']['image_arr'][4]; endif;?>" />

                        <div id="image_div_img_5" class="image_div_img"><?php if(!empty($view_data['good_info']['image_thumb'][5])): ?><img src="<?php echo $view_data['good_info']['image_thumb'][5]; ?>" /><a title="删除" onclick="delete_image(5);">X</a><?php endif ?></div>
                        <input id="image_5" type="hidden" name="image_arr[5]" value="<?php if(!empty($view_data['good_info']['image_arr'][5])): echo $view_data['good_info']['image_arr'][5]; endif;?>" />
                        <div id="image_div_img_6" class="image_div_img"><?php if(!empty($view_data['good_info']['image_thumb'][6])): ?><img src="<?php echo $view_data['good_info']['image_thumb'][6]; ?>" /><a title="删除" onclick="delete_image(6);">X</a><?php endif ?></div>
                        <input id="image_6" type="hidden" name="image_arr[6]" value="<?php if(!empty($view_data['good_info']['image_arr'][6])): echo $view_data['good_info']['image_arr'][6]; endif;?>" />
                        <div id="image_div_img_7" class="image_div_img"><?php if(!empty($view_data['good_info']['image_thumb'][7])): ?><img src="<?php echo $view_data['good_info']['image_thumb'][7]; ?>" /><a title="删除" onclick="delete_image(7);">X</a><?php endif ?></div>
                        <input id="image_7" type="hidden" name="image_arr[7]" value="<?php if(!empty($view_data['good_info']['image_arr'][7])): echo $view_data['good_info']['image_arr'][7]; endif;?>" />
                    </div>


                </div>
            </div>

            <div id="good_attr_list" class="js_tab_content_div form_content">
                <div class="unit">
                    <label class="attr_lable">属性名称</label>
                    <label class="attr_lable">属性值</label>
                    <label class="attr_lable">排序</label>
                    <input class="input_button" type="button" value="添加属性"  onclick="add_attr();">
                </div>

                <?php if(!empty($view_data['good_info'])): ?>

                <?php foreach ($view_data['good_info']['attr_list'] as $attr_index => $attr): ?>
                <div class="unit" attr_index="<?php echo $attr_index; ?>">
                    <input class="attr_input" name="attr_list[<?php echo $attr_index; ?>][name]" type="text" value="<?php echo $attr['name']; ?>" />
                    <input class="attr_input" name="attr_list[<?php echo $attr_index; ?>][value]" type="text" value="<?php echo $attr['value']; ?>" />
                    <input class="attr_input" name="attr_list[<?php echo $attr_index; ?>][order]" type="text" value="<?php echo $attr['order']; ?>" />
                    <input class="js_remove_attr input_button" type="button" value="删除">
                </div>
                <?php endforeach ?>

                <?php else: ?>

                <?php for($i = 0; $i < 5; $i++): ?>
                <div class="unit" attr_index="<?php echo $i; ?>">
                    <input class="attr_input" name="attr_list[<?php echo $i; ?>][name]" type="text" value="" />
                    <input class="attr_input" name="attr_list[<?php echo $i; ?>][value]" type="text" value="" />
                    <input class="attr_input" name="attr_list[<?php echo $i; ?>][order]" type="text" value="" />
                    <input class="js_remove_attr input_button" type="button" value="删除">
                </div>
                <?php endfor;?>

                <?php endif ?>

            </div>

            <div class="js_tab_content_div form_content">
                <div id="good_sattr_list">
                    <div class="unit">
                        <label class="attr_lable">规格属性名称</label>
                        <label class="attr_lable">排序</label>
                        <input class="input_button" type="button" value="添加规格属性"  onclick="add_sattr();">
                    </div>

                    <?php if(!empty($view_data['good_info'])): ?>

                    <?php foreach ($view_data['good_info']['sattr_list'] as $sattr_index => $sattr): ?>
                    <div class="unit" sattr_index="<?php echo $sattr_index; ?>">
                        <input class="js_sattr_name attr_input" name="sattr_list[<?php echo $sattr_index; ?>][name]" type="text" value="<?php echo $sattr['name']; ?>" />
                        <input class="attr_input" name="sattr_list[<?php echo $sattr_index; ?>][order]" type="text" value="<?php echo $sattr['order']; ?>" />
                        <input class="js_remove_sattr input_button" type="button" value="删除">
                    </div>
                    <?php endforeach ?>

                    <?php else: ?>

                    <?php for($i = 0; $i < 2; $i++): ?>
                    <div class="unit" sattr_index="<?php echo $i; ?>">
                        <input class="js_sattr_name attr_input" name="sattr_list[<?php echo $i; ?>][name]" type="text" value="规格属性名称" />
                        <input class="attr_input" name="sattr_list[<?php echo $i; ?>][order]" type="text" value="" />
                        <input class="js_remove_sattr input_button" type="button" value="删除">
                    </div>
                    <?php endfor;?>

                    <?php endif ?>

                </div>

                <hr/>


                <div id="good_number_grade_list">
                    <div class="unit">
                        <label class="attr_lable">起订数量</label>
                        <label class="attr_lable">止订数量</label>
                        <label class="attr_lable">排序</label>
                        <input class="input_button" type="button" value="添加数量范围"  onclick="add_number_grade();">
                    </div>

                    <?php if(!empty($view_data['good_info'])): ?>

                        <?php foreach ($view_data['good_info']['number_grade_list'] as $number_grade_index => $number_grade): ?>
                            <div class="unit" number_grade_index="<?php echo $number_grade_index; ?>">
                                <input class="js_number_grade_number_min attr_input" name="number_grade_list[<?php echo $number_grade_index; ?>][number_min]" type="text"
                                       value="<?php echo $number_grade['number_min']; ?>" />
                                <input class="js_number_grade_number_max attr_input" name="number_grade_list[<?php echo $number_grade_index; ?>][number_max]" type="text"
                                       value="<?php echo $number_grade['number_max']; ?>" />
                                <input class="attr_input" name="number_grade_list[<?php echo $number_grade_index; ?>][order]" type="text"
                                       value="<?php echo $number_grade['order']; ?>" />
                                <input class="js_remove_number_grade input_button" type="button" value="删除">
                            </div>
                        <?php endforeach ?>

                    <?php else: ?>

                            <div class="unit" number_grade_index="0">
                                <input class="js_number_grade_number_min attr_input" name="number_grade_list[0][number_min]" type="text" value="0" />
                                <input class="js_number_grade_number_max attr_input" name="number_grade_list[0][number_max]" type="text" value="0" />
                                <input class="attr_input" name="number_grade_list[0][order]" type="text" value="" />
                                <input class="js_remove_number_grade input_button" type="button" value="删除">
                            </div>

                    <?php endif ?>

                </div>

                <hr/>



                <div id="good_spec_list">
                    <div class="unit">
                        <?php if(!empty($view_data['good_info'])): ?>

                        <?php foreach ($view_data['good_info']['sattr_list'] as $sattr_index => $sattr): ?>
                        <label class="attr_lable good_spec_list_label_col_<?php echo $sattr_index; ?>"><?php echo $sattr['name']; ?></label>
                        <?php endforeach ?>

                        <?php else: ?>

                        <?php for($i = 0; $i < 2; $i++): ?>
                        <label class="attr_lable good_spec_list_label_col_<?php echo $i; ?>">规格属性名称</label>
                        <?php endfor;?>

                        <?php endif ?>


                        <?php /* <label class="attr_lable">价格</label> */ ?>
                        <label class="attr_lable">排序</label>
                        <input class="input_button" type="button" value="添加规格"  onclick="add_spec();">
                    </div>



                    <?php if(!empty($view_data['good_info'])): ?>

                    <?php foreach ($view_data['good_info']['spec_list'] as $spec_index => $spec): ?>
                    <div class="unit spec_unit <?php if(($spec_index+1)%2 == 0): ?>unit_even<?php else: ?>unit_odd<?php endif; ?>" spec_index="<?php echo $spec_index; ?>">
                        <div class="spec_sattr_div">
                            <?php foreach ($view_data['good_info']['sattr_list'] as $sattr_index => $sattr): ?>
                            <input class="attr_input good_spec_list_input_col_<?php echo $sattr_index; ?>" name="spec_list[<?php echo $spec_index; ?>][sattr_value_list][<?php echo $sattr_index; ?>]" type="text" value="<?php echo $spec['sattr_value_list'][$sattr['id']]['value']; ?>" />
                            <?php endforeach ?>

                            <?php /* <input class="attr_input" name="spec_list[<?php echo $spec_index; ?>][price]" type="text" value="<?php echo $spec['price']; ?>" /> */ ?>
                            <input class="attr_input" name="spec_list[<?php echo $spec_index; ?>][order]" type="text" value="<?php echo $spec['order']; ?>" />
                            <input class="js_remove_spec input_button" type="button" value="删除">
                        </div>

                        <div class="spec_number_grade_div">
                            <div class="unit">
                                <label class="attr_lable">数量范围</label>
                                <label class="attr_lable">价格</label>
                            </div>

                            <?php foreach ($view_data['good_info']['number_grade_list'] as $number_grade_index => $number_grade): ?>
                            <div class="unit spec_number_grade_<?php echo $number_grade_index; ?>" spec_number_grade_index="<?php echo $number_grade_index; ?>">
                                <label class="attr_lable">
                                    <span class="spec_number_grade_number_min
                                        spec_number_grade_number_min_<?php echo $number_grade_index; ?>"><?php echo $number_grade['number_min']; ?></span>-<span class="spec_number_grade_number_max
                                        spec_number_grade_number_max_<?php echo $number_grade_index; ?>"><?php echo $number_grade['number_max']; ?></span>
                                </label>
                                <input class="attr_input" name="spec_list[<?php echo $spec_index; ?>][number_grade_price_list][<?php echo $number_grade_index; ?>]"
                                       type="text" value="<?php echo $spec['number_grade_price_list'][$number_grade['id']]['price']; ?>" />
                            </div>
                            <?php endforeach ?>
                        </div>
                    </div>
                    <?php endforeach ?>


                    <?php else: ?>

                    <div class="unit spec_unit unit_odd" spec_index="0">
                        <div class="spec_sattr_div">
                            <?php for($i = 0; $i < 2; $i++): ?>
                            <input class="attr_input good_spec_list_input_col_<?php echo $i; ?>" name="spec_list[0][sattr_value_list][<?php echo $i; ?>]" type="text" value="" />
                            <?php endfor;?>

                            <?php /* <input class="attr_input" name="spec_list[0][price]" type="text" value="" /> */ ?>

                            <input class="attr_input" name="spec_list[0][order]" type="text" value="" />
                            <input class="js_remove_spec input_button" type="button" value="删除">
                        </div>

                        <div class="spec_number_grade_div">
                            <div class="unit">
                                <label class="attr_lable">数量范围</label>
                                <label class="attr_lable">价格</label>
                            </div>

                            <div class="unit spec_number_grade_0" spec_number_grade_index="0">
                                <label class="attr_lable"><span class="spec_number_grade_number_min spec_number_grade_number_min_0">0</span>-<span class="spec_number_grade_number_max spec_number_grade_number_max_0">0</span></label>
                                <input class="attr_input" name="spec_list[0][number_grade_price_list][0]" type="text" value="" />
                            </div>
                        </div>
                    </div>

                    <?php endif ?>

                </div>

            </div>

            <div class="js_tab_content_div form_content">
                <!--<textarea class="editor" name="description" rows="25" cols="98"><?php if(!empty($view_data['good_info'])): echo $view_data['good_info']['description']; endif;?></textarea>-->
                <script id="good_editor" name="description" type="text/plain" style="width:810px;height:500px;"><?php if(!empty($view_data['good_info'])): echo $view_data['good_info']['description']; endif;?></script>
            </div>

            <div class="js_tab_content_div form_content">
                <textarea id="textarea_after_sale_service" name="after_sale_service"><?php if(!empty($view_data['good_info'])): echo $view_data['good_info']['after_sale_service']; endif; ?></textarea>
            </div>

        </blockquote>
    </div>

    <div id="add_good_form_div" class="form_content">
        <div class="unit">
            <label></label>
            <input class="input_submit" type="submit" value="提交" />
        </div>
    </div>
</form>

<div id="good_attr_clone">
    <div class="unit" attr_index="{attr_index}">
        <input class="attr_input" name="attr_list[{attr_index}][name]" type="text" value="" />
        <input class="attr_input" name="attr_list[{attr_index}][value]" type="text" value="" />
        <input class="attr_input" name="attr_list[{attr_index}][order]" type="text" value="" />
        <input class="js_remove_attr input_button" type="button" value="删除">
    </div>
</div>

<div id="good_sattr_clone">
    <div class="unit" sattr_index="{sattr_index}">
        <input class="js_sattr_name attr_input" name="sattr_list[{sattr_index}][name]" type="text" value="规格属性名称" />
        <input class="attr_input" name="sattr_list[{sattr_index}][order]" type="text" value="" />
        <input class="js_remove_sattr input_button" type="button" value="删除">
    </div>
</div>

<div id="good_number_grade_clone">
    <div class="unit" number_grade_index="{number_grade_index}">
        <input class="js_number_grade_number_min attr_input" name="number_grade_list[{number_grade_index}][number_min]" type="text" value="0" />
        <input class="js_number_grade_number_max attr_input" name="number_grade_list[{number_grade_index}][number_max]" type="text" value="0" />
        <input class="attr_input" name="number_grade_list[{number_grade_index}][order]" type="text" value="" />
        <input class="js_remove_number_grade input_button" type="button" value="删除">
    </div>
</div>

<div id="good_spec_clone">
    <div class="unit spec_unit {unit_odd_even}" spec_index="{spec_index}">
        <div class="spec_sattr_div">

            <?php if(!empty($view_data['good_info'])): ?>

            <?php foreach ($view_data['good_info']['sattr_list'] as $sattr_index => $sattr): ?>
            <input class="attr_input good_spec_list_input_col_<?php echo $sattr_index; ?>" name="spec_list[{spec_index}][sattr_value_list][<?php echo $sattr_index; ?>]" type="text" value="" />
            <?php endforeach ?>

            <?php else: ?>

            <?php for($i = 0; $i < 2; $i++): ?>
            <input class="attr_input good_spec_list_input_col_<?php echo $i; ?>" name="spec_list[{spec_index}][sattr_value_list][<?php echo $i; ?>]" type="text" value="" />
            <?php endfor;?>

            <?php endif; ?>


            <?php /* <input class="attr_input" name="spec_list[{spec_index}][price]" type="text" value="" /> */ ?>
            <input class="attr_input" name="spec_list[{spec_index}][order]" type="text" value="" />
            <input class="js_remove_spec input_button" type="button" value="删除">
        </div>

        <div class="spec_number_grade_div">
            <div class="unit">
                <label class="attr_lable">数量范围</label>
                <label class="attr_lable">价格</label>
            </div>


            <?php if(!empty($view_data['good_info'])): ?>

            <?php foreach ($view_data['good_info']['number_grade_list'] as $number_grade_index => $number_grade): ?>
            <div class="unit spec_number_grade_<?php echo $number_grade_index; ?>" spec_number_grade_index="<?php echo $number_grade_index; ?>">
                <label class="attr_lable">
                    <span class="spec_number_grade_number_min
                        spec_number_grade_number_min_<?php echo $number_grade_index; ?>"><?php echo $number_grade['number_min']; ?></span>-<span class="spec_number_grade_number_max
                        spec_number_grade_number_max_<?php echo $number_grade_index; ?>"><?php echo $number_grade['number_max']; ?></span>
                </label>
                <input class="attr_input" name="spec_list[{spec_index}][number_grade_price_list][<?php echo $number_grade_index; ?>]" type="text" value="" />
            </div>
            <?php endforeach; ?>

            <?php else: ?>

            <div class="unit spec_number_grade_0" spec_number_grade_index="0">
                <label class="attr_lable"><span class="spec_number_grade_number_min spec_number_grade_number_min_0">0</span>-<span class="spec_number_grade_number_max spec_number_grade_number_max_0">0</span></label>
                <input class="attr_input" name="spec_list[{spec_index}][number_grade_price_list][0]" type="text" value="" />
            </div>

            <?php endif; ?>
        </div>
    </div>
</div>

<div id="good_spec_list_label_col_clone">
    <label class="attr_lable good_spec_list_label_col_{sattr_index}">规格属性名称</label>
</div>

<div id="good_spec_list_input_col_clone">
    <input class="attr_input good_spec_list_input_col_{sattr_index}" name="spec_list[{spec_index}][sattr_value_list][{sattr_index}]" type="text" value="" />
</div>

<div id="good_spec_list_number_grade_clone">
    <div class="unit spec_number_grade_{spec_number_grade_index}" spec_number_grade_index="{spec_number_grade_index}">
        <label class="attr_lable"><span class="spec_number_grade_number_min spec_number_grade_number_min_{spec_number_grade_index}">0</span>-<span class="spec_number_grade_number_max spec_number_grade_number_max_{spec_number_grade_index}">0</span></label>
        <input class="attr_input" name="spec_list[{spec_index}][number_grade_price_list][{spec_number_grade_index}]" type="text" value="" />
    </div>
</div>

<script type="text/javascript">

function active_tab(active_index){

    if(!active_index){
        active_index = 0;
    }

    //活动标题
    $('.js_tab_title_li').each(function(index, element) {
        if(index === active_index){
            $(this).addClass('active');
        }else{
            $(this).removeClass('active');
        }
    });

    //显示活动内容，隐藏其他内容
    $('.js_tab_content_div').each(function(index, element) {
        if(index === active_index){
            $(this).show();
        }else{
            $(this).hide();
        }
    });
}

function add_attr(){
    var last_attr_index = parseInt($('#good_attr_list .unit:last').attr('attr_index'));
    //alert(last_attr_index); return false;
    var next_attr_index = last_attr_index + 1;
    var good_attr_clone = $('#good_attr_clone').clone();
    good_attr_clone.html(good_attr_clone.html().replace(/\{attr_index\}/g, next_attr_index.toString()));
    $('#good_attr_list').append(good_attr_clone.html());
}

function add_sattr(){
    var last_sattr_index = parseInt($('#good_sattr_list .unit:last').attr('sattr_index'));
    //alert(last_sattr_index); return false;
    var next_sattr_index = last_sattr_index + 1;
    var good_sattr_clone = $('#good_sattr_clone').clone();
    good_sattr_clone.html(good_sattr_clone.html().replace(/\{sattr_index\}/g, next_sattr_index.toString()));
    $('#good_sattr_list').append(good_sattr_clone.html());

    //添加列【名】
    //var last_label_col_class = '.good_spec_list_label_col_' + last_sattr_index;
    var good_spec_list_label_col_clone = $('#good_spec_list_label_col_clone').clone();
    good_spec_list_label_col_clone.html(good_spec_list_label_col_clone.html().replace(/\{sattr_index\}/g, next_sattr_index.toString()));
    $('.good_spec_list_label_col_' + last_sattr_index).after(good_spec_list_label_col_clone.html());

    //添加列【输入框】
    $('#good_spec_list .good_spec_list_input_col_' + last_sattr_index).each(function(index, element) {
        var spec_unit = $(this).parent().parent();
        var spec_index = spec_unit.attr('spec_index');
        //alert(spec_index); return false;

        var good_spec_list_input_col_clone = $('#good_spec_list_input_col_clone').clone();
        good_spec_list_input_col_clone.html(good_spec_list_input_col_clone.html().replace(/\{sattr_index\}/g, next_sattr_index.toString()));
        good_spec_list_input_col_clone.html(good_spec_list_input_col_clone.html().replace(/\{spec_index\}/g, spec_index.toString()));
        $(this).after(good_spec_list_input_col_clone.html());
    });

    //【$('#good_spec_clone .good_spec_list_input_col_' + last_sattr_index)】添加列【输入框】
    $('#good_spec_clone .good_spec_list_input_col_' + last_sattr_index).each(function(index, element) {
        var good_spec_list_input_col_clone = $('#good_spec_list_input_col_clone').clone();
        good_spec_list_input_col_clone.html(good_spec_list_input_col_clone.html().replace(/\{sattr_index\}/g, next_sattr_index.toString()));
        $(this).after(good_spec_list_input_col_clone.html());
    });
}

function add_number_grade(){
    var last_number_grade_index = parseInt($('#good_number_grade_list .unit:last').attr('number_grade_index'));
    //alert(last_number_grade_index); return false;
    var next_number_grade_index = last_number_grade_index + 1;
    var good_number_grade_clone = $('#good_number_grade_clone').clone();
    good_number_grade_clone.html(good_number_grade_clone.html().replace(/\{number_grade_index\}/g, next_number_grade_index.toString()));
    $('#good_number_grade_list').append(good_number_grade_clone.html());

    //为每个【规格】，添加【数量范围】
    $('#good_spec_list .spec_number_grade_div').each(function(index, element) {
        var spec_unit = $(this).parent();
        var spec_index = spec_unit.attr('spec_index');
        //alert(spec_index); return false;

        var good_spec_list_number_grade_clone = $('#good_spec_list_number_grade_clone').clone();
        good_spec_list_number_grade_clone.html(good_spec_list_number_grade_clone.html().replace(/\{spec_number_grade_index\}/g, next_number_grade_index.toString()));
        good_spec_list_number_grade_clone.html(good_spec_list_number_grade_clone.html().replace(/\{spec_index\}/g, spec_index.toString()));
        $(this).append(good_spec_list_number_grade_clone.html());
    });


    //为【$('#good_spec_clone .spec_number_grade_div')】，添加【数量范围】
    $('#good_spec_clone .spec_number_grade_div').each(function(index, element) {
        var good_spec_list_number_grade_clone = $('#good_spec_list_number_grade_clone').clone();
        good_spec_list_number_grade_clone.html(good_spec_list_number_grade_clone.html().replace(/\{spec_number_grade_index\}/g, next_number_grade_index.toString()));
        $(this).append(good_spec_list_number_grade_clone.html());
    });
}



function add_spec(){
    var last_spec_index = parseInt($('#good_spec_list .spec_unit:last').attr('spec_index'));
    //alert(last_spec_index); return false;
    var next_spec_index = last_spec_index + 1;
    var unit_odd_even = 'unit_odd';
    if((next_spec_index+1)%2 == 0){
        unit_odd_even = 'unit_even';
    }
    var good_spec_clone = $('#good_spec_clone').clone();
    good_spec_clone.html(good_spec_clone.html().replace(/\{spec_index\}/g, next_spec_index.toString()));
    good_spec_clone.html(good_spec_clone.html().replace(/\{unit_odd_even\}/g, unit_odd_even));
    $('#good_spec_list').append(good_spec_clone.html());
}

function save_good(){
    var good_data = $('#add_good_form').serialize();
    //alert(good_data); return false;

    $.ajax({
        type: 'POST',
        url: "<?php echo $view_data['save_url']; ?>",
        //data: $('#add_good_form').serialize(),
        data: good_data,
        dataType: 'json',
        success: function(rdata){
            if(rdata.status <= 0){
                alert(rdata.message);
            }else{
                alert(rdata.message);
                window.top.location.replace('<?php echo $view_data['index_url']; ?>');
            }

            return false;
        }
    });

    return false;
}


//删除图片
function delete_image(index){
	$('#image_div_img_' + index).html('');
	$('#image_' + index).val('');
	$("#image_file_upload").uploadify('disable', false);
}



$(function(){
    //初始化活动标题，活动标签
    active_tab();

    $('.js_tab_title_li').click(function(){
        var active_index = $(this).index();
        active_tab(active_index);
    });

    $('.js_remove_attr').live('click', function(){
        var attr_unit = $(this).parent();
        var attr_index = attr_unit.attr('attr_index');
        if(attr_index == '0'){
            alert('第一个保留，不能删除');
        }else{
            attr_unit.remove();
        }
    });


    //修改【规格属性名称】时，同步列【名】
    $('.js_sattr_name').live('blur', function(){
        var sattr_name = $(this).val()

        var sattr_unit = $(this).parent();
        var sattr_index = sattr_unit.attr('sattr_index');

        $('.good_spec_list_label_col_' + sattr_index).html(sattr_name);
    });

    $('.js_remove_sattr').live('click', function(){
        var sattr_unit = $(this).parent();
        var sattr_index = sattr_unit.attr('sattr_index');
        if(sattr_index == '0'){
            alert('第一个保留，不能删除');
        }else{
            sattr_unit.remove();

            //删除列【名】
            $('.good_spec_list_label_col_' + sattr_index).remove();

            //删除列【输入框】
            $('#good_spec_list .good_spec_list_input_col_' + sattr_index).remove();

            //【$('#good_spec_clone .good_spec_list_input_col_' + sattr_index)】删除列【输入框】
            $('#good_spec_clone .good_spec_list_input_col_' + sattr_index).remove();
        }
    });

    //修改某一【价格范围】【起订数量】时，同步【规格】对应【价格范围】【起订数量】
    $('.js_number_grade_number_min').live('blur', function(){
        var number_grade_number_min = $(this).val();

        var number_grade_unit = $(this).parent();
        var number_grade_index = number_grade_unit.attr('number_grade_index');

        $('.spec_number_grade_number_min_' + number_grade_index).html(number_grade_number_min);
    });

    //修改某一【价格范围】【止订数量】时，同步【规格】对应【价格范围】【止订数量】
    $('.js_number_grade_number_max').live('blur', function(){
        var number_grade_number_max = $(this).val()

        var number_grade_unit = $(this).parent();
        var number_grade_index = number_grade_unit.attr('number_grade_index');

        $('.spec_number_grade_number_max_' + number_grade_index).html(number_grade_number_max);
    });

    $('.js_remove_number_grade').live('click', function(){
        var number_grade_unit = $(this).parent();
        var number_grade_index = number_grade_unit.attr('number_grade_index');
        if(number_grade_index == '0'){
            alert('第一个保留，不能删除');
        }else{
            number_grade_unit.remove();

            //为每个【规格】，删除对应【数量范围】
            $('#good_spec_list .spec_number_grade_' + number_grade_index).remove();

            ////为【$('#good_spec_clone .spec_number_grade_div')】，删除【数量范围】
            $('#good_spec_clone .spec_number_grade_' + number_grade_index).remove();
        }
    });



    $('.js_remove_spec').live('click', function(){
        var spec_unit = $(this).parent().parent();
        var spec_index = spec_unit.attr('spec_index');
        if(spec_index == '0'){
            alert('第一个保留，不能删除');
        }else{
            spec_unit.remove();
        }
    });

    //上传图片
	$("#image_file_upload").uploadify({
		'buttonText' : '上&nbsp;&nbsp;传',
		'formData'     : {
            'id'             : '<?php if(!empty($view_data['good_info']['id'])): echo $view_data['good_info']['id']; else: ?>0<?php endif ?>',
			'timestamp'      : '<?php echo $view_data['timestamp'];?>',
			'token'          : '<?php echo $view_data['token'];?>'
		},
		'swf' : '/module/background/pc/packs/uploadify/uploadify.swf',
        'uploader' : '<?php echo $this->get_url(array('route' => 'pc_background_good_upload'), true); ?>',
		'onUploadSuccess' : function(file, rdataStr, response) {
            //alert(rdataStr); return false;
			var rdata = $.parseJSON(rdataStr);
            if(rdata.status == 1){
				var filled  = false;
				var disable = true;
				$('.image_div_img').each(function(index, element){
					if($(element).html() == ''){
						if(filled === false){
							var imgHtml = '<img src="' + rdata.data.image_thumb + '" /><a title="删除" onclick="delete_image(' + index + ');">X</a>';
							$(element).html(imgHtml);
							$('#image_' + index).val(rdata.data.image);

							filled = true;
						}else{
							disable = false;
							return false;
						}
					}
				});

				//若填满图片，则禁用上传
				if(disable){
					$("#image_file_upload").uploadify('disable', true);
				}
			}
		},

//        'onUploadError' : function(file, errorCode, errorMsg, errorString) {
//            alert('The file ' + file.name + ' could not be uploaded: ' + errorString + "\n" + errorCode + "\n" + errorMsg);
//        }

        //'onInit': checkFull
	});


    var ue = UE.getEditor('good_editor');

});

</script>